//+------------------------------------------------------------------+
//|                                                     csvtrade.mq4 |
//|                                               Nicolas Charrieau  |
//|                                                             V1.1 |
//+------------------------------------------------------------------+
/*
APPEARS TO WORK BUT NOT FULLY TESTED

This is a crude "API" for MT4. It allows external programs to control MT4 to execute, modify, close and delete trades

Store in experts/scripts and compile

This script Polls folder experts/files every Repeat_Delay_Seconds for a file commandfile.txt
If it exists, reads a single trade command as per examples below.:

OrderSend,AUDUSD,OP_BUY,1,Ask,5,0,0,Order1,9999,0,Orange
OrderSend,AUDUSD,OP_BUYSTOP,1,0.7670,5,0,0,Order2,9999,0,Orange
OrderModify,Order1,0.7695,0.7620,0.7720,0,Orange
OrderClose,Order1,1,Bid,5,Purple
OrderDelete,Order1

Note that the format of the CSV lines is similar to the original function calls.

An important point about managing existing orders
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The commands OrderModify, OrderClose and OrderDelete locate the order that they are targetting by its Comment,
NOT by its ticket number.

If the command in commandfile.txt is successful it is deleted and the command is written to commandfile_log.txt
Unsuccessful commandfiles are renamed "FAILED command <TimeLocal>.txt"

Maintains list of open orders in openorders.txt in format:
OrderOpenTime,OrderComment,OrderMagicNumber,OrderSymbol,OrderType,OrderLots,OrderOpenPrice,OrderStopLoss,OrderTakeProfit

*/


#include <stderror.mqh>
#include <stdlib.mqh>

#property show_inputs
extern bool Trade_Debug = false; // turn on for debug messages
extern int Repeat_Delay_Seconds = 10; // poll repeat delay

#define BASE_FOLDER "csvtrade\\"
#define COMMAND_FILENAME "commandfile.txt"
#define RESULT_FILENAME "resultfile.txt"
#define COMMAND_FILE_PREFIX "commandfile"
#define COMMAND_FILE_LOGNAME "commandfile_log.txt"
#define OPEN_ORDERS_FILENAME "openorders.txt"
#define FAILED_PREFIX "FAILED command "


int start()
{
	
	int maxargs = 10;
	string varray[0];
	ArrayResize(varray, maxargs);

   string key;
   string lastkey="";
	string str;
	string cmd;
	FileDelete(COMMAND_FILENAME);    
	while(true)
	{
      int handle=FileOpen(COMMAND_FILENAME,FILE_CSV|FILE_READ,';');
      if(handle>0){
         key = FileReadString(handle);
         if(key != lastkey){
         Print("key = "+key);
            lastkey = key;
            cmd = FileReadString(handle);
            Print("command = "+cmd);
            for(int arg=0;arg<maxargs;arg++){ 
         	   str=FileReadString(handle);
         	   if(GetLastError() == 0){
                  if(str != ""){
                     Print("argument["+arg+"] = "+str);
                     varray[arg] = str;
                  }else{
                     break;
                  }
               }else{
                  break;
               }
            }
           //reinitError();
            string result = key+";"+execCommand(cmd,varray);
            int handle2=FileOpen(RESULT_FILENAME, FILE_CSV|FILE_WRITE, ';');
            if(handle2>0)
            {
            FileWrite(handle2,result);
            FileClose(handle2);
            }
         } 
         FileClose(handle);
         
      }
   
   }

   return(0);
}
//+------------------------------------------------------------------+



string execCommand(string cmd,string gsa_108[]) {
int li_4 = StrToInteger(cmd);
string ls_8 = "";
switch (li_4) {
      case 0:
         ls_8 = "" + iBars(gsa_108[0], StrToInteger(gsa_108[1]));
         Print("iBars", ", ", "symbol=", gsa_108[0], ", ", "timeframe=", gsa_108[1]);
         break;
      case 1:
         ls_8 = "" + iBarShift(gsa_108[0], StrToInteger(gsa_108[1]), StrToTime(gsa_108[2]), StrToInteger(gsa_108[3]));
         Print("iBarShift", ", ", "symbol=", gsa_108[0], ", ", "timeframe=", gsa_108[1], ", ", "time=", gsa_108[2], ", ", "exact=", gsa_108[3]);
         break;
      case 2:
         ls_8 = "" + iClose(gsa_108[0], StrToInteger(gsa_108[1]), StrToInteger(gsa_108[2]));
         Print("iClose", ", ", "symbol=", gsa_108[0], ", ", "timeframe=", gsa_108[1], ", ", "shift=", gsa_108[2]);
         break;
      case 3:
         ls_8 = "" + iHigh(gsa_108[0], StrToInteger(gsa_108[1]), StrToInteger(gsa_108[2]));
         Print("iHigh", ", ", "symbol=", gsa_108[0], ", ", "timeframe=", gsa_108[1], ", ", "shift=", gsa_108[2]);
         break;
      case 4:
         ls_8 = "" + iLow(gsa_108[0], StrToInteger(gsa_108[1]), StrToInteger(gsa_108[2]));
         Print("iLow", ", ", "symbol=", gsa_108[0], ", ", "timeframe=", gsa_108[1], ", ", "shift=", gsa_108[2]);
         break;
      case 5:
         ls_8 = "" + iOpen(gsa_108[0], StrToInteger(gsa_108[1]), StrToInteger(gsa_108[2]));
         Print("iOpen", ", ", "symbol=", gsa_108[0], ", ", "timeframe=", gsa_108[1], ", ", "shift=", gsa_108[2]);
         break;
      case 6:
         ls_8 = "" + iVolume(gsa_108[0], StrToInteger(gsa_108[1]), StrToInteger(gsa_108[2]));
         Print("iVolume", ", ", "symbol=", gsa_108[0], ", ", "timeframe=", gsa_108[1], ", ", "shift=", gsa_108[2]);
         break;
      case 7:
         ls_8 = "" + iTime(gsa_108[0], StrToInteger(gsa_108[1]), StrToInteger(gsa_108[2]));
         Print("iTime", ", ", "symbol=", gsa_108[0], ", ", "timeframe=", gsa_108[1], ", ", "shift=", gsa_108[2]);
         break;
      case 8:
         ls_8 = "" + iLowest(gsa_108[0], StrToInteger(gsa_108[1]), StrToInteger(gsa_108[2]), StrToInteger(gsa_108[3]), StrToInteger(gsa_108[4]));
         Print("iLowest", ", ", "symbol=", gsa_108[0], ", ", "timeframe=", gsa_108[1], ", ", "type=", gsa_108[2], ", ", "count=", gsa_108[3], ", ", "start=", gsa_108[4]);
         break;
      case 9:
         ls_8 = "" + iHighest(gsa_108[0], StrToInteger(gsa_108[1]), StrToInteger(gsa_108[2]), StrToInteger(gsa_108[3]), StrToInteger(gsa_108[4]));
         Print("iHighest", ", ", "symbol=", gsa_108[0], ", ", "timeframe=", gsa_108[1], ", ", "type=", gsa_108[2], ", ", "count=", gsa_108[3], ", ", "start=", gsa_108[4]);
         break;
      case 10:
         ls_8 = "" + AccountBalance();
         Print("AccountBalance", "");
         break;
      case 11:
         ls_8 = "" + AccountCredit();
         Print("AccountCredit", "");
         break;
      case 12:
         ls_8 = "" + AccountCompany();
         Print("AccountCompany", "");
         break;
      case 13:
         ls_8 = "" + AccountCurrency();
         Print("AccountCurrency", "");
         break;
      case 14:
         ls_8 = "" + AccountEquity();
         Print("AccountEquity", "");
         break;
      case 15:
         ls_8 = "" + AccountFreeMargin();
         Print("AccountFreeMargin", "");
         break;
      case 16:
         ls_8 = "" + AccountMargin();
         Print("AccountMargin", "");
         break;
      case 17:
         ls_8 = "" + AccountName();
         Print("AccountName", "");
         break;
      case 18:
         ls_8 = "" + AccountNumber();
         Print("AccountNumber", "");
         break;
      case 19:
         ls_8 = "" + AccountProfit();
         Print("AccountProfit", "");
         break;
      case 20:
         ls_8 = "" + GetLastError();
         Print("GetLastError", "");
         break;
      case 21:
         ls_8 = "" + IsConnected();
         Print("IsConnected", "");
         break;
      case 22:
         ls_8 = "" + IsDemo();
         Print("IsDemo", "");
         break;
      case 23:
         ls_8 = "" + IsTesting();
         Print("IsTesting", "");
         break;
      case 24:
         ls_8 = "" + IsVisualMode();
         Print("IsVisualMode", "");
         break;
      case 25:
         ls_8 = "" + GetTickCount();
         Print("GetTickCount", "");
         break;
      case 26:
         Comment(gsa_108[0]);
         Print("Comment", ", ", "comments=", gsa_108[0]);
         break;
      case 27:
         ls_8 = "" + MarketInfo(gsa_108[0], StrToInteger(gsa_108[1]));
         Print("MarketInfo", ", ", "symbol=", gsa_108[0], ", ", "type=", gsa_108[1]);
         break;
      case 28:
         Print(gsa_108[0]);
         Print("Print", ", ", "comments=", gsa_108[0]);
         break;
      case 29:
         ls_8 = "" + Day();
         Print("Day", "");
         break;
      case 30:
         ls_8 = "" + DayOfWeek();
         Print("DayOfWeek", "");
         break;
      case 31:
         ls_8 = "" + DayOfYear();
         Print("DayOfYear", "");
         break;
      case 32:
         ls_8 = "" + Hour();
         Print("Hour", "");
         break;
      case 33:
         ls_8 = "" + Minute();
         Print("Minute", "");
         break;
      case 34:
         ls_8 = "" + Month();
         Print("Month", "");
         break;
      case 35:
         ls_8 = "" + Seconds();
         Print("Seconds", "");
         break;
      case 36:
         ls_8 = "" + TimeCurrent();
         Print("TimeCurrent", "");
         break;
      case 37:
         ls_8 = "" + Year();
         Print("Year", "");
         break;
      case 38:
         ls_8 = "" + ObjectCreate(gsa_108[0], StrToInteger(gsa_108[1]), StrToInteger(gsa_108[2]), StrToTime(gsa_108[3]), StrToDouble(gsa_108[4]), StrToTime(gsa_108[5]), StrToDouble(gsa_108[6]), StrToTime(gsa_108[7]), StrToDouble(gsa_108[8]));
         Print("ObjectCreate", ", ", "name=", gsa_108[0], ", ", "type=", gsa_108[1], ", ", "window=", gsa_108[2], ", ", "time1=", gsa_108[3], ", ", "price1=", gsa_108[4], ", ", "time2=", gsa_108[5], ", ", "price2=", gsa_108[6], ", ", "time3=", gsa_108[7], ", ", "price3=", gsa_108[8]);
         break;
      case 39:
         ls_8 = "" + ObjectCreate(gsa_108[0], StrToInteger(gsa_108[1]), StrToInteger(gsa_108[2]), StrToTime(gsa_108[3]), StrToDouble(gsa_108[4]));
         Print("ObjectCreate", ", ", "name=", gsa_108[0], ", ", "type=", gsa_108[1], ", ", "window=", gsa_108[2], ", ", "time1=", gsa_108[3], ", ", "price1=", gsa_108[4]);
         break;
      case 40:
         ls_8 = "" + ObjectCreate(gsa_108[0], StrToInteger(gsa_108[1]), StrToInteger(gsa_108[2]), StrToTime(gsa_108[3]), StrToDouble(gsa_108[4]), StrToTime(gsa_108[5]), StrToDouble(gsa_108[6]));
         Print("ObjectCreate", ", ", "name=", gsa_108[0], ", ", "type=", gsa_108[1], ", ", "window=", gsa_108[2], ", ", "time1=", gsa_108[3], ", ", "price1=", gsa_108[4], ", ", "time2=", gsa_108[5], ", ", "price2=", gsa_108[6]);
         break;
      case 41:
         ls_8 = "" + ObjectDelete(gsa_108[0]);
         Print("ObjectDelete", ", ", "name=", gsa_108[0]);
         break;
      case 42:
         ls_8 = "" + ObjectGet(gsa_108[0], StrToInteger(gsa_108[1]));
         Print("ObjectGet", ", ", "name=", gsa_108[0], ", ", "index=", gsa_108[1]);
         break;
      case 43:
         ls_8 = "" + ObjectSet(gsa_108[0], StrToInteger(gsa_108[1]), StrToDouble(gsa_108[2]));
         Print("ObjectSet", ", ", "name=", gsa_108[0], ", ", "index=", gsa_108[1], ", ", "value=", gsa_108[2]);
         break;
      case 44:
         ls_8 = "" + ObjectGetFiboDescription(gsa_108[0], StrToInteger(gsa_108[1]));
         Print("ObjectGetFiboDescription", ", ", "name=", gsa_108[0], ", ", "index=", gsa_108[1]);
         break;
      case 45:
         ls_8 = "" + ObjectSetFiboDescription(gsa_108[0], StrToInteger(gsa_108[1]), gsa_108[2]);
         Print("ObjectSetFiboDescription", ", ", "name=", gsa_108[0], ", ", "index=", gsa_108[1], ", ", "text=", gsa_108[2]);
         break;
      case 46:
         ls_8 = "" + ObjectSetText(gsa_108[0], gsa_108[1], StrToInteger(gsa_108[2]), gsa_108[3], StrToInteger(gsa_108[4]));
         Print("ObjectSetText", ", ", "name=", gsa_108[0], ", ", "text=", gsa_108[1], ", ", "font_size=", gsa_108[2], ", ", "font=", gsa_108[3], ", ", "text_color=", gsa_108[4]);
         break;
      case 47:
         ls_8 = "" + ObjectsTotal(StrToInteger(gsa_108[0]));
         Print("ObjectsTotal", ", ", "type=", gsa_108[0]);
         break;
      case 48:
         ls_8 = "" + ObjectType(gsa_108[0]);
         Print("ObjectType", ", ", "name=", gsa_108[0]);
         break;
      case 49:
         ls_8 = "" + iAC(gsa_108[0], StrToInteger(gsa_108[1]), StrToInteger(gsa_108[2]));
         Print("iAC", ", ", "symbol=", gsa_108[0], ", ", "timeframe=", gsa_108[1], ", ", "shift=", gsa_108[2]);
         break;
      case 50:
         ls_8 = "" + iAD(gsa_108[0], StrToInteger(gsa_108[1]), StrToInteger(gsa_108[2]));
         Print("iAD", ", ", "symbol=", gsa_108[0], ", ", "timeframe=", gsa_108[1], ", ", "shift=", gsa_108[2]);
         break;
      case 51:
         ls_8 = "" + iAlligator(gsa_108[0], StrToInteger(gsa_108[1]), StrToInteger(gsa_108[2]), StrToInteger(gsa_108[3]), StrToInteger(gsa_108[4]), StrToInteger(gsa_108[5]), StrToInteger(gsa_108[6]), StrToInteger(gsa_108[7]), StrToInteger(gsa_108[8]), StrToInteger(gsa_108[9]), StrToInteger(gsa_108[10]), StrToInteger(gsa_108[11]));
         Print("iAlligator", ", ", "symbol=", gsa_108[0], ", ", "timeframe=", gsa_108[1], ", ", "jawPeriod=", gsa_108[2], ", ", "jawShift=", gsa_108[3], ", ", "teethPeriod=", gsa_108[4], ", ", "teethShift=", gsa_108[5], ", ", "lipsPeriod=", gsa_108[6], ", ", "lipsShift=", gsa_108[7], ", ", "maMethod=", gsa_108[8], ", ", "appliedPrice=", gsa_108[9], ", ", "mode=", gsa_108[10], ", ", "shift=", gsa_108[11]);
         break;
      case 52:
         ls_8 = "" + iADX(gsa_108[0], StrToInteger(gsa_108[1]), StrToInteger(gsa_108[2]), StrToInteger(gsa_108[3]), StrToInteger(gsa_108[4]), StrToInteger(gsa_108[5]));
         Print("iADX", ", ", "symbol=", gsa_108[0], ", ", "timeframe=", gsa_108[1], ", ", "period=", gsa_108[2], ", ", "appliedPrice=", gsa_108[3], ", ", "mode=", gsa_108[4], ", ", "shift=", gsa_108[5]);
         break;
      case 53:
         ls_8 = "" + iATR(gsa_108[0], StrToInteger(gsa_108[1]), StrToInteger(gsa_108[2]), StrToInteger(gsa_108[3]));
         Print("iATR", ", ", "symbol=", gsa_108[0], ", ", "timeframe=", gsa_108[1], ", ", "period=", gsa_108[2], ", ", "shift=", gsa_108[3]);
         break;
      case 54:
         ls_8 = "" + iAO(gsa_108[0], StrToInteger(gsa_108[1]), StrToInteger(gsa_108[2]));
         Print("iAO", ", ", "symbol=", gsa_108[0], ", ", "timeframe=", gsa_108[1], ", ", "shift=", gsa_108[2]);
         break;
      case 55:
         ls_8 = "" + iBearsPower(gsa_108[0], StrToInteger(gsa_108[1]), StrToInteger(gsa_108[2]), StrToInteger(gsa_108[3]), StrToInteger(gsa_108[4]));
         Print("iBearsPower", ", ", "symbol=", gsa_108[0], ", ", "timeframe=", gsa_108[1], ", ", "period=", gsa_108[2], ", ", "appliedPrice=", gsa_108[3], ", ", "shift=", gsa_108[4]);
         break;
      case 56:
         ls_8 = "" + iBands(gsa_108[0], StrToInteger(gsa_108[1]), StrToInteger(gsa_108[2]), StrToInteger(gsa_108[3]), StrToInteger(gsa_108[4]), StrToInteger(gsa_108[5]), StrToInteger(gsa_108[6]), StrToInteger(gsa_108[7]));
         Print("iBands", ", ", "symbol=", gsa_108[0], ", ", "timeframe=", gsa_108[1], ", ", "period=", gsa_108[2], ", ", "deviation=", gsa_108[3], ", ", "bandsShift=", gsa_108[4], ", ", "appliedPrice=", gsa_108[5], ", ", "mode=", gsa_108[6], ", ", "shift=", gsa_108[7]);
         break;
      case 57:
         ls_8 = "" + iBullsPower(gsa_108[0], StrToInteger(gsa_108[1]), StrToInteger(gsa_108[2]), StrToInteger(gsa_108[3]), StrToInteger(gsa_108[4]));
         Print("iBullsPower", ", ", "symbol=", gsa_108[0], ", ", "timeframe=", gsa_108[1], ", ", "period=", gsa_108[2], ", ", "appliedPrice=", gsa_108[3], ", ", "shift=", gsa_108[4]);
         break;
      case 58:
         ls_8 = "" + iCCI(gsa_108[0], StrToInteger(gsa_108[1]), StrToInteger(gsa_108[2]), StrToInteger(gsa_108[3]), StrToInteger(gsa_108[4]));
         Print("iCCI", ", ", "symbol=", gsa_108[0], ", ", "timeframe=", gsa_108[1], ", ", "period=", gsa_108[2], ", ", "appliedPrice=", gsa_108[3], ", ", "shift=", gsa_108[4]);
         break;
      case 59:
         ls_8 = "" + iCustom(gsa_108[0], StrToInteger(gsa_108[1]), gsa_108[2], StrToInteger(gsa_108[3]), StrToInteger(gsa_108[4]));
         Print("iCustom", ", ", "symbol=", gsa_108[0], ", ", "timeframe=", gsa_108[1], ", ", "name=", gsa_108[2], ", ", "mode=", gsa_108[3], ", ", "shift=", gsa_108[4]);
         break;
      case 60:
         ls_8 = "" + iDeMarker(gsa_108[0], StrToInteger(gsa_108[1]), StrToInteger(gsa_108[2]), StrToInteger(gsa_108[3]));
         Print("iDeMarker", ", ", "symbol=", gsa_108[0], ", ", "timeframe=", gsa_108[1], ", ", "period=", gsa_108[2], ", ", "shift=", gsa_108[3]);
         break;
      case 61:
         ls_8 = "" + iEnvelopes(gsa_108[0], StrToInteger(gsa_108[1]), StrToInteger(gsa_108[2]), StrToInteger(gsa_108[3]), StrToInteger(gsa_108[4]), StrToInteger(gsa_108[5]), StrToDouble(gsa_108[6]), StrToInteger(gsa_108[7]), StrToInteger(gsa_108[8]));
         Print("iEnvelopes", ", ", "symbol=", gsa_108[0], ", ", "timeframe=", gsa_108[1], ", ", "maPeriod=", gsa_108[2], ", ", "maMethod=", gsa_108[3], ", ", "maShitf=", gsa_108[4], ", ", "appliedPrice=", gsa_108[5], ", ", "deviation=", gsa_108[6], ", ", "mode=", gsa_108[7], ", ", "shift=", gsa_108[8]);
         break;
      case 62:
         ls_8 = "" + iForce(gsa_108[0], StrToInteger(gsa_108[1]), StrToInteger(gsa_108[2]), StrToInteger(gsa_108[3]), StrToInteger(gsa_108[4]), StrToInteger(gsa_108[5]));
         Print("iForce", ", ", "symbol=", gsa_108[0], ", ", "timeframe=", gsa_108[1], ", ", "period=", gsa_108[2], ", ", "maMethod=", gsa_108[3], ", ", "appliedPrice=", gsa_108[4], ", ", "shift=", gsa_108[5]);
         break;
      case 63:
         ls_8 = "" + iFractals(gsa_108[0], StrToInteger(gsa_108[1]), StrToInteger(gsa_108[2]), StrToInteger(gsa_108[3]));
         Print("iFractals", ", ", "symbol=", gsa_108[0], ", ", "timeframe=", gsa_108[1], ", ", "mode=", gsa_108[2], ", ", "shift=", gsa_108[3]);
         break;
      case 64:
         ls_8 = "" + iGator(gsa_108[0], StrToInteger(gsa_108[1]), StrToInteger(gsa_108[2]), StrToInteger(gsa_108[3]), StrToInteger(gsa_108[4]), StrToInteger(gsa_108[5]), StrToInteger(gsa_108[6]), StrToInteger(gsa_108[7]), StrToInteger(gsa_108[8]), StrToInteger(gsa_108[9]), StrToInteger(gsa_108[10]), StrToInteger(gsa_108[11]));
         Print("iGator", ", ", "symbol=", gsa_108[0], ", ", "timeframe=", gsa_108[1], ", ", "jawPeriod=", gsa_108[2], ", ", "jawShift=", gsa_108[3], ", ", "teethPeriod=", gsa_108[4], ", ", "teethShift=", gsa_108[5], ", ", "lipsPeriod=", gsa_108[6], ", ", "lipsShift=", gsa_108[7], ", ", "maMethod=", gsa_108[8], ", ", "appliedPrice=", gsa_108[9], ", ", "mode=", gsa_108[10], ", ", "shift=", gsa_108[11]);
         break;
      case 65:
         ls_8 = "" + iBWMFI(gsa_108[0], StrToInteger(gsa_108[1]), StrToInteger(gsa_108[2]));
         Print("iBWMFI", ", ", "symbol=", gsa_108[0], ", ", "timeframe=", gsa_108[1], ", ", "shift=", gsa_108[2]);
         break;
      case 66:
         ls_8 = "" + iMomentum(gsa_108[0], StrToInteger(gsa_108[1]), StrToInteger(gsa_108[2]), StrToInteger(gsa_108[3]), StrToInteger(gsa_108[4]));
         Print("iMomentum", ", ", "symbol=", gsa_108[0], ", ", "timeframe=", gsa_108[1], ", ", "period=", gsa_108[2], ", ", "appliedPrice=", gsa_108[3], ", ", "shift=", gsa_108[4]);
         break;
      case 67:
         ls_8 = "" + iMFI(gsa_108[0], StrToInteger(gsa_108[1]), StrToInteger(gsa_108[2]), StrToInteger(gsa_108[3]));
         Print("iMFI", ", ", "symbol=", gsa_108[0], ", ", "timeframe=", gsa_108[1], ", ", "period=", gsa_108[2], ", ", "shift=", gsa_108[3]);
         break;
      case 68:
         ls_8 = "" + iMA(gsa_108[0], StrToInteger(gsa_108[1]), StrToInteger(gsa_108[2]), StrToInteger(gsa_108[3]), StrToInteger(gsa_108[4]), StrToInteger(gsa_108[5]), StrToInteger(gsa_108[6]));
         Print("iMA", ", ", "symbol=", gsa_108[0], ", ", "timeframe=", gsa_108[1], ", ", "period=", gsa_108[2], ", ", "maShift=", gsa_108[3], ", ", "maMethod=", gsa_108[4], ", ", "appliedPrice=", gsa_108[5], ", ", "shift=", gsa_108[6]);
         break;
      case 69:
         ls_8 = "" + iOsMA(gsa_108[0], StrToInteger(gsa_108[1]), StrToInteger(gsa_108[2]), StrToInteger(gsa_108[3]), StrToInteger(gsa_108[4]), StrToInteger(gsa_108[5]), StrToInteger(gsa_108[6]));
         Print("iOsMA", ", ", "symbol=", gsa_108[0], ", ", "timeframe=", gsa_108[1], ", ", "fastEMAPeriod=", gsa_108[2], ", ", "slowEMAPeriod=", gsa_108[3], ", ", "signalPeriod=", gsa_108[4], ", ", "appliedPrice=", gsa_108[5], ", ", "shift=", gsa_108[6]);
         break;
      case 70:
         ls_8 = "" + iMACD(gsa_108[0], StrToInteger(gsa_108[1]), StrToInteger(gsa_108[2]), StrToInteger(gsa_108[3]), StrToInteger(gsa_108[4]), StrToInteger(gsa_108[5]), StrToInteger(gsa_108[6]), StrToInteger(gsa_108[7]));
         Print("iMACD", ", ", "symbol=", gsa_108[0], ", ", "timeframe=", gsa_108[1], ", ", "fastEMAPeriod=", gsa_108[2], ", ", "slowEMAPeriod=", gsa_108[3], ", ", "signalPeriod=", gsa_108[4], ", ", "appliedPrice=", gsa_108[5], ", ", "mode=", gsa_108[6], ", ", "shift=", gsa_108[7]);
         break;
      case 71:
         ls_8 = "" + iOBV(gsa_108[0], StrToInteger(gsa_108[1]), StrToInteger(gsa_108[2]), StrToInteger(gsa_108[3]));
         Print("iOBV", ", ", "symbol=", gsa_108[0], ", ", "timeframe=", gsa_108[1], ", ", "appliedPrice=", gsa_108[2], ", ", "shift=", gsa_108[3]);
         break;
      case 72:
         ls_8 = "" + iSAR(gsa_108[0], StrToInteger(gsa_108[1]), StrToDouble(gsa_108[2]), StrToDouble(gsa_108[3]), StrToInteger(gsa_108[4]));
         Print("iSAR", ", ", "symbol=", gsa_108[0], ", ", "timeframe=", gsa_108[1], ", ", "step=", gsa_108[2], ", ", "maximum=", gsa_108[3], ", ", "shift=", gsa_108[4]);
         break;
      case 73:
         ls_8 = "" + iRSI(gsa_108[0], StrToInteger(gsa_108[1]), StrToInteger(gsa_108[2]), StrToInteger(gsa_108[3]), StrToInteger(gsa_108[4]));
         Print("iRSI", ", ", "symbol=", gsa_108[0], ", ", "timeframe=", gsa_108[1], ", ", "period=", gsa_108[2], ", ", "appliedPrice=", gsa_108[3], ", ", "shift=", gsa_108[4]);
         break;
      case 74:
         ls_8 = "" + iRVI(gsa_108[0], StrToInteger(gsa_108[1]), StrToInteger(gsa_108[2]), StrToInteger(gsa_108[3]), StrToInteger(gsa_108[4]));
         Print("iRVI", ", ", "symbol=", gsa_108[0], ", ", "timeframe=", gsa_108[1], ", ", "period=", gsa_108[2], ", ", "mode=", gsa_108[3], ", ", "shift=", gsa_108[4]);
         break;
      case 75:
         ls_8 = "" + iStdDev(gsa_108[0], StrToInteger(gsa_108[1]), StrToInteger(gsa_108[2]), StrToInteger(gsa_108[3]), StrToInteger(gsa_108[4]), StrToInteger(gsa_108[5]), StrToInteger(gsa_108[6]));
         Print("iStdDev", ", ", "symbol=", gsa_108[0], ", ", "timeframe=", gsa_108[1], ", ", "maPeriod=", gsa_108[2], ", ", "maShift=", gsa_108[3], ", ", "maMethod=", gsa_108[4], ", ", "appliedPrice=", gsa_108[5], ", ", "shift=", gsa_108[6]);
         break;
      case 76:
         ls_8 = "" + iStochastic(gsa_108[0], StrToInteger(gsa_108[1]), StrToInteger(gsa_108[2]), StrToInteger(gsa_108[3]), StrToInteger(gsa_108[4]), StrToInteger(gsa_108[5]), StrToInteger(gsa_108[6]), StrToInteger(gsa_108[7]), StrToInteger(gsa_108[8]));
         Print("iStochastic", ", ", "symbol=", gsa_108[0], ", ", "timeframe=", gsa_108[1], ", ", "kPeriod=", gsa_108[2], ", ", "dPeriod=", gsa_108[3], ", ", "slowing=", gsa_108[4], ", ", "maMethod=", gsa_108[5], ", ", "priceField=", gsa_108[6], ", ", "mode=", gsa_108[7], ", ", "shift=", gsa_108[8]);
         break;
      case 77:
         ls_8 = "" + iWPR(gsa_108[0], StrToInteger(gsa_108[1]), StrToInteger(gsa_108[2]), StrToInteger(gsa_108[3]));
         Print("iWPR", ", ", "symbol=", gsa_108[0], ", ", "timeframe=", gsa_108[1], ", ", "period=", gsa_108[2], ", ", "shift=", gsa_108[3]);
         break;
      case 78:
         ls_8 = "" + OrderClose(StrToInteger(gsa_108[0]), StrToDouble(gsa_108[1]), StrToDouble(gsa_108[2]), StrToInteger(gsa_108[3]), StrToInteger(gsa_108[4]));
         Print("OrderClose", ", ", "ticket=", gsa_108[0], ", ", "lots=", gsa_108[1], ", ", "price=", gsa_108[2], ", ", "slippage=", gsa_108[3], ", ", "arrowColor=", gsa_108[4]);
         break;
      case 79:
         ls_8 = "" + OrderCloseBy(StrToInteger(gsa_108[0]), StrToInteger(gsa_108[1]), StrToInteger(gsa_108[2]));
         Print("OrderCloseBy", ", ", "ticket=", gsa_108[0], ", ", "opposite=", gsa_108[1], ", ", "arrowColor=", gsa_108[2]);
         break;
      case 80:
         ls_8 = "" + OrderClosePrice();
         Print("OrderClosePrice", "");
         break;
      case 81:
         ls_8 = "" + OrderCloseTime();
         Print("OrderCloseTime", "");
         break;
      case 82:
         ls_8 = "" + OrderComment();
         Print("OrderComment", "");
         break;
      case 83:
         ls_8 = "" + OrderCommission();
         Print("OrderCommission", "");
         break;
      case 84:
         ls_8 = "" + OrderDelete(StrToInteger(gsa_108[0]), StrToInteger(gsa_108[1]));
         Print("OrderDelete", ", ", "ticket=", gsa_108[0], ", ", "arrowColor=", gsa_108[1]);
         break;
      case 85:
         ls_8 = "" + OrderExpiration();
         Print("OrderExpiration", "");
         break;
      case 86:
         ls_8 = "" + OrderLots();
         Print("OrderLots", "");
         break;
      case 87:
         ls_8 = "" + OrderMagicNumber();
         Print("OrderMagicNumber", "");
         break;
      case 88:
         ls_8 = "" + OrderModify(StrToInteger(gsa_108[0]), StrToDouble(gsa_108[1]), StrToDouble(gsa_108[2]), StrToDouble(gsa_108[3]), StrToTime(gsa_108[4]), StrToInteger(gsa_108[5]));
         Print("OrderModify", ", ", "ticket=", gsa_108[0], ", ", "price=", gsa_108[1], ", ", "stoploss=", gsa_108[2], ", ", "takeprofit=", gsa_108[3], ", ", "expiration=", gsa_108[4], ", ", "arrowColor=", gsa_108[5]);
         break;
      case 89:
         ls_8 = "" + OrderOpenPrice();
         Print("OrderOpenPrice", "");
         break;
      case 90:
         ls_8 = "" + OrderOpenTime();
         Print("OrderOpenTime", "");
         break;
      case 91:
         OrderPrint();
         Print("OrderPrint", "");
         break;
      case 92:
         ls_8 = "" + OrderProfit();
         Print("OrderProfit", "");
         break;
      case 93:
         ls_8 = "" + OrderSelect(StrToInteger(gsa_108[0]), StrToInteger(gsa_108[1]), StrToInteger(gsa_108[2]));
         Print("OrderSelect", ", ", "index=", gsa_108[0], ", ", "select=", gsa_108[1], ", ", "pool=", gsa_108[2]);
         break;
      case 94:
         ls_8 = "" + OrderSend(gsa_108[0], StrToInteger(gsa_108[1]), StrToDouble(gsa_108[2]), StrToDouble(gsa_108[3]), StrToInteger(gsa_108[4]), StrToDouble(gsa_108[5]), StrToDouble(gsa_108[6]), gsa_108[7], StrToInteger(gsa_108[8]), StrToTime(gsa_108[9]), StrToInteger(gsa_108[10]));
         Print("OrderSend", ", ", "symbol=", gsa_108[0], ", ", "cmd=", gsa_108[1], ", ", "volume=", gsa_108[2], ", ", "price=", gsa_108[3], ", ", "slippage=", gsa_108[4], ", ", "stoploss=", gsa_108[5], ", ", "takeprofit=", gsa_108[6], ", ", "comment=", gsa_108[7], ", ", "magic=", gsa_108[8], ", ", "expiration=", gsa_108[9], ", ", "arrowColor=", gsa_108[10]);
         break;
      case 95:
         ls_8 = "" + OrdersHistoryTotal();
         Print("OrdersHistoryTotal", "");
         break;
      case 96:
         ls_8 = "" + OrderStopLoss();
         Print("OrderStopLoss", "");
         break;
      case 97:
         ls_8 = "" + OrdersTotal();
         Print("OrdersTotal", "");
         break;
      case 98:
         ls_8 = "" + OrderSwap();
         Print("OrderSwap", "");
         break;
      case 99:
         ls_8 = "" + OrderSymbol();
         Print("OrderSymbol", "");
         break;
      case 100:
         ls_8 = "" + OrderTakeProfit();
         Print("OrderTakeProfit", "");
         break;
      case 101:
         ls_8 = "" + OrderTicket();
         Print("OrderTicket", "");
         break;
      case 102:
         ls_8 = "" + OrderType();
         Print("OrderType", "");
         break;
      case 103:
         ls_8 = "" + IsTradeContextBusy();
         Print("IsTradeContextBusy", "");
         break;
      case 104:
         ls_8 = "" + RefreshRates();
         Print("RefreshRates", "");
         break;
      case 105:
         ls_8 = "" + AccountStopoutLevel();
         Print("AccountStopoutLevel", "");
         break;
      case 106:
         ls_8 = "" + AccountStopoutMode();
         Print("AccountStopoutMode", "");
         break;
      case 107:
         ls_8 = "" + MessageBox(gsa_108[0], gsa_108[1], StrToInteger(gsa_108[2]));
         Print("MessageBox", ", ", "text=", gsa_108[0], ", ", "caption=", gsa_108[1], ", ", "flags=", gsa_108[2]);
         break;
      case 108:
         ls_8 = "" + UninitializeReason();
         Print("UninitializeReason", "");
         break;
      case 109:
         ls_8 = "" + IsTradeAllowed();
         Print("IsTradeAllowed", "");
         break;
      case 110:
         ls_8 = "" + IsStopped();
         Print("IsStopped", "");
         break;
      case 111:
         ls_8 = "" + IsOptimization();
         Print("IsOptimization", "");
         break;
      case 112:
         ls_8 = "" + IsLibrariesAllowed();
         Print("IsLibrariesAllowed", "");
         break;
      case 113:
         ls_8 = "" + IsDllsAllowed();
         Print("IsDllsAllowed", "");
         break;
      case 114:
         ls_8 = "" + IsExpertEnabled();
         Print("IsExpertEnabled", "");
         break;
      case 115:
         ls_8 = "" + AccountFreeMarginCheck(gsa_108[0], StrToInteger(gsa_108[1]), StrToDouble(gsa_108[2]));
         Print("AccountFreeMarginCheck", ", ", "symbol=", gsa_108[0], ", ", "cmd=", gsa_108[1], ", ", "volume=", gsa_108[2]);
         break;
      case 116:
         ls_8 = "" + AccountFreeMarginMode();
         Print("AccountFreeMarginMode", "");
         break;
      case 117:
         ls_8 = "" + AccountLeverage();
         Print("AccountLeverage", "");
         break;
      case 118:
         ls_8 = "" + AccountServer();
         Print("AccountServer", "");
         break;
      case 119:
         ls_8 = "" + TerminalCompany();
         Print("TerminalCompany", "");
         break;
      case 120:
         ls_8 = "" + TerminalName();
         Print("TerminalName", "");
         break;
      case 121:
         ls_8 = "" + TerminalPath();
         Print("TerminalPath", "");
         break;
      case 122:
         Alert(gsa_108[0]);
         Print("Alert", ", ", "arg=", gsa_108[0]);
         break;
      case 123:
         PlaySound(gsa_108[0]);
         Print("PlaySound", ", ", "filename=", gsa_108[0]);
         break;
      case 124:
         ls_8 = "" + ObjectDescription(gsa_108[0]);
         Print("ObjectDescription", ", ", "name=", gsa_108[0]);
         break;
      case 125:
         ls_8 = "" + ObjectFind(gsa_108[0]);
         Print("ObjectFind", ", ", "name=", gsa_108[0]);
         break;
      case 126:
         ls_8 = "" + ObjectGetShiftByValue(gsa_108[0], StrToDouble(gsa_108[1]));
         Print("ObjectGetShiftByValue", ", ", "name=", gsa_108[0], ", ", "value=", gsa_108[1]);
         break;
      case 127:
         ls_8 = "" + ObjectGetValueByShift(gsa_108[0], StrToInteger(gsa_108[1]));
         Print("ObjectGetValueByShift", ", ", "name=", gsa_108[0], ", ", "shift=", gsa_108[1]);
         break;
      case 128:
         ls_8 = "" + ObjectMove(gsa_108[0], StrToInteger(gsa_108[1]), StrToTime(gsa_108[2]), StrToDouble(gsa_108[3]));
         Print("ObjectMove", ", ", "name=", gsa_108[0], ", ", "point=", gsa_108[1], ", ", "time1=", gsa_108[2], ", ", "price1=", gsa_108[3]);
         break;
      case 129:
         ls_8 = "" + ObjectName(StrToInteger(gsa_108[0]));
         Print("ObjectName", ", ", "index=", gsa_108[0]);
         break;
      case 130:
         ls_8 = "" + ObjectsDeleteAll(StrToInteger(gsa_108[0]), StrToInteger(gsa_108[1]));
         Print("ObjectsDeleteAll", ", ", "window=", gsa_108[0], ", ", "type=", gsa_108[1]);
         break;
      case 131:
         ls_8 = "" + iIchimoku(gsa_108[0], StrToInteger(gsa_108[1]), StrToInteger(gsa_108[2]), StrToInteger(gsa_108[3]), StrToInteger(gsa_108[4]), StrToInteger(gsa_108[5]), StrToInteger(gsa_108[6]));
         Print("iIchimoku", ", ", "symbol=", gsa_108[0], ", ", "timeframe=", gsa_108[1], ", ", "tenkan_sen=", gsa_108[2], ", ", "kijun_sen=", gsa_108[3], ", ", "senkou_span_b=", gsa_108[4], ", ", "mode=", gsa_108[5], ", ", "shift=", gsa_108[6]);
         break;
      case 132:
         HideTestIndicators(StrToInteger(gsa_108[0]));
         Print("HideTestIndicators", ", ", "shift=", gsa_108[0]);
         break;
      case 133:
         ls_8 = "" + Period();
         Print("Period", "");
         break;
      case 134:
         ls_8 = "" + Symbol();
         Print("Symbol", "");
         break;
      case 135:
         ls_8 = "" + WindowBarsPerChart();
         Print("WindowBarsPerChart", "");
         break;
      case 136:
         ls_8 = "" + WindowFirstVisibleBar();
         Print("WindowFirstVisibleBar", "");
         break;
      case 137:
         ls_8 = "" + WindowExpertName();
         Print("WindowExpertName", "");
         break;
      case 138:
         ls_8 = "" + WindowFind(gsa_108[0]);
         Print("WindowFind", ", ", "name=", gsa_108[0]);
         break;
      case 139:
         ls_8 = "" + WindowIsVisible(StrToInteger(gsa_108[0]));
         Print("WindowIsVisible", ", ", "index=", gsa_108[0]);
         break;
      case 140:
         ls_8 = "" + WindowPriceMax(StrToInteger(gsa_108[0]));
         Print("WindowPriceMax", ", ", "index=", gsa_108[0]);
         break;
      case 141:
         ls_8 = "" + WindowPriceMin(StrToInteger(gsa_108[0]));
         Print("WindowPriceMin", ", ", "index=", gsa_108[0]);
         break;
      case 142:
         ls_8 = "" + WindowOnDropped();
         Print("WindowOnDropped", "");
         break;
      case 143:
         ls_8 = "" + WindowXOnDropped();
         Print("WindowXOnDropped", "");
         break;
      case 144:
         ls_8 = "" + WindowYOnDropped();
         Print("WindowYOnDropped", "");
         break;
      case 145:
         ls_8 = "" + WindowPriceOnDropped();
         Print("WindowPriceOnDropped", "");
         break;
      case 146:
         ls_8 = "" + WindowTimeOnDropped();
         Print("WindowTimeOnDropped", "");
         break;
      case 147:
         ls_8 = "" + WindowsTotal();
         Print("WindowsTotal", "");
         break;
      case 148:
         ObjectsRedraw();
         Print("WindowRedraw", "");
         break;
      case 149:
         ls_8 = "" + WindowScreenShot(gsa_108[0], StrToInteger(gsa_108[1]), StrToInteger(gsa_108[2]), StrToInteger(gsa_108[3]), StrToInteger(gsa_108[4]), StrToInteger(gsa_108[5]));
         Print("WindowScreenShot", ", ", "filename=", gsa_108[0], ", ", "sizeX=", gsa_108[1], ", ", "sizeY=", gsa_108[2], ", ", "startBar=", gsa_108[3], ", ", "chartScale=", gsa_108[4], ", ", "chartMode=", gsa_108[5]);
         break;
      case 150:
         ls_8 = "" + WindowHandle(gsa_108[0], StrToInteger(gsa_108[1]));
         Print("WindowHandle", ", ", "symbol=", gsa_108[0], ", ", "timeframe=", gsa_108[1]);
      }
      //reinitError();
      string ls_20 = ls_8 + "@" + GetLastError();
      Print("Result=", ls_20);
      return (ls_20);
      
}